<?php

defined("_ARKN_EXEC") or exit("no no, mr. superman no here");
($_SESSION["roleid"] == Roles::Student) or exit("you almost got away with it");
require_once ROOT_FOLDER . "/php/scripts/account_scripts/Account.php";

$studentid = $_SESSION["accountid"];
$basicInfo = $account->studentBasicInfo($studentid);
$departments = $account->studentDepartments($studentid);

print("<script type='text/javascript'>");
print("var courses = new Array();\n");
for($i = 0; $i < count($departments); $i++) {
	$depCourses = $account->studentCourses($studentid, $departments[$i]["departmentid"]);
	if($i == 0)
		$firstDepCourses = $depCourses;
	print("var c$i = new Array();\n");
	for($j = 0; $j < count($depCourses); $j++) {
		print("var c$i$j = new Array();\n");		
		print("c$i$j.push(\"" . htmlEsc($depCourses[$j]["name"]) . "\");\n");
		print("c$i$j.push(\"" . htmlEsc($depCourses[$j]["firstname"]) . " " . htmlEsc($depCourses[$j]["lastname"]) . "\");\n");
		print("c$i$j.push(\"" . htmlEsc($depCourses[$j]["examdate"]) . "\");\n");
		print("c$i$j.push(\"" . htmlEsc($depCourses[$j]["grade"]) . "\");\n");
		print("c$i$j.push(\"" . htmlEsc($depCourses[$j]["credits"]) . "\");\n");		
		print("c$i.push(c$i$j);\n");	
	}
	print("courses.push(c$i);\n");
}
print("</script>");
$payments = $account->studentPayments($studentid);
print("<br />");
print("<br />");

/*
 * Basic information table
 */
print('<div style="width: 100%; text-align: center;">');						// main div
print('<div style="display: inline-block;">');									// centering div
print('<table cellpadding="0" cellspacing="0" class="db-table">');
print("<tr>");
print("<th>Full Name</th>");
print("<th>User Name</th>");
print("<th>Address</th>");
print("<th>Email</th>");
print("</tr>");

print("<tr>");
print("<td>" . htmlEsc($basicInfo["firstname"]) . " " . htmlEsc($basicInfo["lastname"]) . "</td>");
print("<td>" . htmlEsc($basicInfo["username"]) . "</td>");
print("<td>" . htmlEsc($basicInfo["address"]) . "</td>");
print("<td>" . htmlEsc($basicInfo["email"]) . "</td>");
print("</tr>");
print("</table>");

print("</div>");																// centering div
print("</div>");																// main div

print("<br />");
print("<br />");


/*
 * Course Info table
 */
print('<div style="width: 69%; float: left; text-align:center;">');				// align left div

print("<p>Course Information</p>");
print("<p>Department:&nbsp;&nbsp;");
print('<select id="depSelect">');
foreach($departments as $row) {
	print('<option value="' . htmlEsc($row["departmentid"]) . '">');
	print(htmlEsc($row["name"]) . ", " . htmlEsc($row["city"]));
	print("</option>");
}
print("</select>");
print("</p>");

print('<table cellpadding="0" cellspacing="0" id="coursesTable" class="db-table">');
print("<tr>");
print("<th>Name</th>");
print("<th>Teacher</th>");
print("<th>Exam</th>");
print("<th>Grade</th>");
print("<th>Credits</th>");
print("</tr>");

foreach($firstDepCourses as $row) {
	print('<tr class="normalCourseRow">');
	print("<td>" . htmlEsc($row["name"]) . "</td>");
	print("<td>" . htmlEsc($row["firstname"]) . " " . htmlEsc($row["lastname"]) . "</td>");
	print("<td>" . htmlEsc($row["examdate"]) . "</td>");
	print("<td>" . htmlEsc($row["grade"]) . "</td>");
	print("<td>" . htmlEsc($row["credits"]) . "</td>");
	print("</tr>");
}
print("</table>");
print("</div>");																// align left div

/*
 * Payment history table
 */
print('<div style="width: 29%; float: right; text-align:center;">');			// allign right div
print("<p>Payment history</p><br/>");
print('<table cellpadding="0" cellspacing="0" class="db-table">');
print("<tr>");
print("<th>Date</th>");
print("<th>Amount</th>");
print("</tr>");

foreach($payments as $row) {
	print("<tr>");
	print("<td>" . htmlEsc($row["paydate"]) . "</td>");
	print("<td>" . htmlEsc($row["amount"]) . "</td>");
	print("</tr>");
}
print("</table>");
print("</div>");																// allign right div

?>